import G6 from "@antv/g6"
import { nodeEdge } from "@/hooks/graph/editable/generate/generate"

// 图形渲染
export function wRender(arg, wPublicConfig) {
  let { graphInstance } = arg
  const { graphData } = arg
  const { graphOptions } = wPublicConfig
  if (graphInstance) graphInstance.destroy()
  graphInstance = new G6.Graph(graphOptions)
  const nodes = graphData?.nodes
  const edges = graphData?.edges
  nodes?.forEach((node) => {
    nodeEdge(node, '类型转换')
  })
  edges?.forEach((edge) => {
    nodeEdge(edge, '类型转换')
  })
  graphInstance.read(graphData)

  return graphInstance
}